package com.c.ctgproject.adapter.guang

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.c.ctgproject.adapter.ImageCommonRvAdapter
import com.c.ctgproject.adapter.ImageCommonRvV2Adapter
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityPartDetailBinding
import com.c.ctgproject.entity.guang.PartHandlerDetail
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MyObserverHandlerLoading
import com.c.ctgproject.utils.*
import com.c.ctgproject.wiget.common.CarInfoLayout

/**
 *作者:LiBW
 *创建日期: 2021/9/17
 *描述: 配件详情
 */
class PartDetailActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityPartDetailBinding.inflate(layoutInflater) }
    override fun getLayout() = mBinding.root
    private val orderId by lazy { intent.getIntExtra(MyConstants.ORDER_ID, -1) }
    override fun event() {
        ApiMethods.apiSubscribe(ApiMethods.retrofit.partHandlerDetail(orderId), MyObserverHandlerLoading(this, loading) {
            MyLog.d("零件拆解单详情回调:$it")
            val data = getGson().fromJson(it, PartHandlerDetail::class.java).data

            data?.let { bean ->
                mBinding.mContainer1.addView(CarInfoLayout(this, "零件拆解单号", bean.dismantleNo.noDataHandler()))
                val dismantleMethod = when (data.dismantleMethod) {
                    1 -> "毁型"
                    2 -> "拆配件"
                    else -> "暂无数据"
                }
                mBinding.mContainer1.addView(CarInfoLayout(this, "拆解方式", dismantleMethod))
                mBinding.mContainer1.addView(CarInfoLayout(this, "开单时间", bean.createTime.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "计划完成时间", bean.plainFinishTime.noDataHandler()))
            }

            //图片列表
            data?.urlList?.let { list ->
                val adapter = ImageCommonRvV2Adapter(this, list)
                mBinding.mImageRV.adapter = adapter
                mBinding.mImageRV.layoutManager = GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false)
            }

            //列表
            data?.items?.let { list ->
                val adapter = PartHandlerDetailAdapter(this, list)
                mBinding.mRecyclerView.adapter = adapter
                mBinding.mRecyclerView.layoutManager = LinearLayoutManager(this)
            }
        })
    }

    override fun click() {

    }
}